﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using YouHP.Model;

namespace YouHP.Atom
{
    public class PatientEmotion
    {
        static readonly string _spGetEmotion = "getemotion";
        static readonly string _spAddEmotion = "addemotion";

        static readonly string _spGetEmotionType = "getemotiontype";
        static readonly string _spGetAllEmotionTypes = "getallemotiontypes";

        public EmotionInfo GetEmotion(int userid)
        {
            return CBO.FillObject<EmotionInfo>(SqlHelper.ExecuteReader(Common.ConnStr, _spGetEmotion, userid));
        }

        public int AddEmotion(EmotionInfo info)
        {
            SqlParameter[] outParms = new SqlParameter[]  {
                new SqlParameter("@userid", SqlDbType.Int),
                new SqlParameter("@prid", SqlDbType.Int),
                new SqlParameter("@emotiontype", SqlDbType.Int),
                new SqlParameter("@statusdescription", SqlDbType.NVarChar, 500),
                new SqlParameter("@id", SqlDbType.Int)
            };
            outParms[0].Value = info.UserId;
            outParms[1].Value = info.PrId;
            outParms[2].Value = info.EmotionType;
            outParms[3].Value = info.StatusDescription;
            outParms[4].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(Common.ConnStr, CommandType.StoredProcedure, _spAddEmotion, outParms);
            info.Id = Convert.ToInt32(outParms[4].Value.ToString());
            return info.Id; 
        }

        public EmotionTypeInfo GetEmotionType(int typeid)
        {
            return CBO.FillObject<EmotionTypeInfo>(SqlHelper.ExecuteReader(Common.ConnStr, _spGetEmotionType, typeid));
        }

        public List<EmotionTypeInfo> GetAllEmotionTypes()
        {
            return CBO.FillCollection<EmotionTypeInfo>(SqlHelper.ExecuteReader(Common.ConnStr, _spGetAllEmotionTypes));
        }


    }
}
